/*
 * GoogleDocument.java
 *
 */

package pl.edu.pw.mini.adapter.documents;

import com.google.gdata.data.Category;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.docs.DocumentListEntry;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author cdendek
 */
public class GoogleDocument extends Document{
    
    private DocumentListEntry entry;
    private File documentSource;
    private String title;
    
    private static Map<String,Type> categoryMapping=new HashMap<String,Type>();
    
    static{
        categoryMapping.put("spreadsheet",Type.SPREADSHEET);
        categoryMapping.put("document",Type.TEXT);
        categoryMapping.put("presentation",Type.PRESENTATION);
    }
    
    /** Creates a new instance of GoogleDocument */
    public GoogleDocument(DocumentListEntry entry) {
        this.entry=entry;
        title=entry.getTitle().getPlainText();
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setFile(File f) {
    }
    
    public void setTitle(String title){
        //entry.getTitle().getPlainText();
        this.title=title;
        if (entry!=null){
            entry.setTitle(new PlainTextConstruct(title));
        }
    }
    
    public Type getType(){
        Set<Category> cats=entry.getCategories();
        for(Category cat:cats){
            Type t=categoryMapping.get(cat.getLabel());
            if (t!=null){
                return t;
            }
        }
        return Type.UNKNOWN;
    }
    public DateTime getLastEdited(){
        return entry.getEdited();
    }
    
    public Set<String> getFolders(){
        return entry.getFolders();
    }
    
    public String getVersion(){
        return entry.getVersionId();
    }

    public DateTime getUpdated() {
        return entry.getUpdated();
    }

    public String getId() {
        return entry.getId();
    }
    
    public DocumentListEntry getEntry(){
        return entry;
    }
}
